
/**
 * while(scanf()  != EOF)
 * 
 * 遇到空格、换行符会隔断
 */





#include <stdio.h>
#include <stdlib.h>



int main(int argc, char * argv[])
{
    int i, j;
    int M;
    int N;
    int *buf;
    int min_data = 0;
    int max_data = 0;
    int mid = -1;
    scanf("%d", &M);
    if(M <= 0)
    {
        printf("-1");
        return -1;
    }
       
    buf = (int *)malloc(sizeof(int) * M);
    for (i=0; i<M; i++)
    {
        scanf("%d", &(buf[i]));
    }
    
    scanf("%d", &N);
    if(N <= 0 || N > M/2)
    {
        free(buf);
        printf("-1");
        return -1;
    }
    
    for (i=0; i<M; i++)
        for(j=(i+1); j<M; j++)
        {      
            printf("i %d j %d M %d %d %d \n", i, j, M, buf[i], buf[j]);  
            if(buf[i] > buf[j])
            {
                int temp = buf[i];
                buf[i] = buf[j];
                buf[j] = temp;
            }
            else if(buf[i] == buf[j])
            {
                if (j != (M-1))
                {
                    buf[j] = buf[M-1];
                    M --;
                    j--;
                }
                else
                {
                    M--;
                }
            }
        }
    
    if(N > M/2)
    {
        free(buf);
        printf("-1");
        return -1;
    }
    
    for (i=0; i<M; i++)
    {     
        if(i<N)
        {
            max_data += buf[M-i-1];
            min_data += buf[i];
        }        
    }
    printf("%d", min_data + max_data);
    free(buf);
    return 0;
    
}